package org.jeecg.modules.config.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.config.entity.SysConfig;
import org.jeecg.modules.config.mapper.SysConfigMapper;
import org.jeecg.modules.config.service.ISysConfigService;
import org.jeecg.modules.consts.ConstantsContext;
import org.springframework.stereotype.Service;

/**
 * @Description: sys_config
 * @Author: jeecg-boot
 * @Date:   2023-05-05
 * @Version: V1.0
 */
@Service
public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements ISysConfigService {

    @Override
    public String findByCode(String code) {
            String res = ConstantsContext.getConstantsContextVal(code);
            if (res != null) {
                return res;
            }
            LambdaQueryWrapper<SysConfig> wrapper = new LambdaQueryWrapper();
            wrapper.eq(SysConfig::getCode, code);
            SysConfig sysConfig = baseMapper.selectOne(wrapper);
            if (sysConfig != null) {
                //添加字典context
                ConstantsContext.putConstant(code, sysConfig.getValue());
                return sysConfig.getValue();
            }
            return null;
        }
}
